package com.lg.base_common_library.utils;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by ligang on 2017/10/8.
 * description：
 */


public class CollectionUtil {
    public static <T> Collection<T> move(List<T> paramList, int paramInt1, int paramInt2) {
        int i = -1 + paramList.size();
        if ((paramInt1 == paramInt2) || (paramInt1 > i) || (paramInt2 > i)) {
            return paramList;
        }
        if (paramInt1 < paramInt2) {
            Object localObject2 = paramList.get(paramInt1);
            Object localObject3 = paramList.get(paramInt2);
            paramList.remove(paramInt1);
            paramList.add(1 + paramList.indexOf(localObject3), (T) localObject2);
            return paramList;
        }
        Object localObject1 = paramList.get(paramInt1);
        paramList.remove(paramInt1);
        paramList.add(paramInt2, (T) localObject1);
        return paramList;
    }

    public static <T> T[] toArray(List<T> paramList, Class<T> paramClass) {
        if ((paramList == null) || (paramList.size() == 0)) {
            return null;
        }
        int i = paramList.size();
        try {
            Object[] arrayOfObject = paramList.toArray((Object[]) Array.newInstance(paramClass, i));
            return (T[]) arrayOfObject;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return null;
    }

    public static <T> T[] toArray(Set<T> paramSet, Class<T> paramClass) {
        if ((paramSet == null) || (paramSet.size() == 0)) {
            return null;
        }
        int i = paramSet.size();
        try {
            Object[] arrayOfObject = paramSet.toArray((Object[]) Array.newInstance(paramClass, i));
            return (T[]) arrayOfObject;
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return null;
    }

    public static <T> ArrayList<T> toArrayList(T[] paramArrayOfT) {
        if ((paramArrayOfT == null) || (paramArrayOfT.length == 0)) {
            return null;
        }
        ArrayList localArrayList = new ArrayList();
        Collections.addAll(localArrayList, paramArrayOfT);
        return localArrayList;
    }

    public static <T> HashSet<T> toHashSet(T[] paramArrayOfT) {
        if ((paramArrayOfT == null) || (paramArrayOfT.length == 0)) {
            return null;
        }
        HashSet localHashSet = new HashSet();
        Collections.addAll(localHashSet, paramArrayOfT);
        return localHashSet;
    }
}

